package xyz.migle.sc.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//@SpringBootApplication
//@EnableDiscoveryClient
//@RestController
public class ScApp001Robbin {
//    //@Autowired
//    //LoadBalancerClient loadBalancerClient;
//
//    @Autowired
//    RestTemplate restTemplate ;
//
//    @RequestMapping("/robbin")
//    public String testRobbin() {
//        //String url = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/dc";
//        //String url = serviceInstance.getUri().toString();
//        //System.out.println(url);
//        //return "i am sc-demo-app-001,i depend on "+ url +":" + restTemplate.getForObject(url, String.class);
//        //使用robbin后，不再显式的通过service name 拼接url再做调用，直接使用service name 加路径调用
//        //Spring Cloud Ribbon有一个拦截器，它能够在这里进行实际调用的时候，自动的去选取服务实例，并将实际要请求的IP地址和端口替换这里的服务名，从而完成服务接口的调用
//        return "i am sc-demo-app-001,i depend on " + restTemplate.getForObject("http://sc-demo-base-001", String.class);
//
//
//    }
//
//    @Bean
//    @LoadBalanced
//    public RestTemplate restTemplate() {
//        return new RestTemplate();
//    }
//
//    public static void main(String[] args) {
//         SpringApplication.run(ScApp001Robbin.class,args);
//    }

}

